<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <div>{{msg}}</div>
        <div>{{msg.split('').reverse().join('')}}</div>
        <div>{{reverserString}}</div>
        <div>{{reverserString}}</div>
        <div>{{reverseMessage()}}</div>
        <div>{{reverseMessage()}}</div>

    </div>
    <script>
        /*
            计算属性

            计算属性与方法的区别：
                    计算属性有缓存，methods方法没有缓存
        */
        var vm = new Vue({
            el:'#app',
            data:{
                msg:'hello',
                num:100
            },
            methods:{
                reverseMessage:function(){
                    console.log('methods');
                    return this.msg.split('').reverse().join('');
                }
            },
            computed: {
                reverserString:function(){
                    console.log('computes');
                    // return this.msg.split('').reverse().join('');
                    var total = 0;
                    for(var i=0;i<=this.num;i++){
                        total +=i;
                    }
                    return total;
                }
            },
        })
    </script>
</body>
</html>